package com.jingtai.platform.service.shop.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jingtai.common.enums.DeleteFlagEnum;
import com.jingtai.common.template.ResultMapInfo;
import com.jingtai.core.entity.shop.ShufflingFigure;
import com.jingtai.core.mapper.shop.ShufflingFigureMapper;
import com.jingtai.platform.service.shop.ShufflingFigureService;
import com.jingtai.platform.util.ResultUtil;
import com.jingtai.platform.util.UrlToMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


/**
 * 轮播图表 impl
 *
 * @author sunlaiqian
 * @date 2020-12-02 18:31:32
 */
@Service
public class ShufflingFigureServiceImpl extends ServiceImpl<ShufflingFigureMapper, ShufflingFigure> implements ShufflingFigureService {

    @Autowired
    private ShufflingFigureService shufflingFigureService;

    @Override
    public ResultUtil ShufflingFigurelist(Integer page, Integer limit, String conditions){
        QueryWrapper<ShufflingFigure> wrapper = new QueryWrapper<>();
        Map<String, String> map = UrlToMap.paramToMap(conditions);
        for(Map.Entry<String, String> entry : map.entrySet()){
            wrapper.like(entry.getKey(), entry.getValue());
        }
        wrapper.eq("delete_flag", DeleteFlagEnum.NOT_DELETE.getCode());
        return new ResultUtil(ResultMapInfo.GETSUCCESS,shufflingFigureService.page(new Page<>(page,limit),wrapper));
    }

    @Override
    public ResultUtil addShufflingFigure(ShufflingFigure shufflingFigure) {
        boolean save = shufflingFigureService.save(shufflingFigure);
        return new ResultUtil(save ? ResultMapInfo.ADDSUCCESS:ResultMapInfo.ADDFAIL);
    }

    @Override
    public ResultUtil getShufflingFigureById(Long id) {
        ShufflingFigure shufflingFigure = shufflingFigureService.getById(id);
        return shufflingFigure == null ?  new ResultUtil(ResultMapInfo.GETFAIL) : new ResultUtil(ResultMapInfo.GETSUCCESS,shufflingFigure);
    }

    @Override
    public ResultUtil delShufflingFigureById(Long id) {
        ShufflingFigure shufflingFigure = new ShufflingFigure();
        shufflingFigure.setId(id);
        shufflingFigure.setDeleteFlag(DeleteFlagEnum.DELETE.getCode());
        boolean delState = shufflingFigureService.updateById(shufflingFigure);
        return delState ?  new ResultUtil(ResultMapInfo.DELETESUCCESS) : new ResultUtil(ResultMapInfo.DELETEFAIL);
    }

    @Override
    public ResultUtil editShufflingFigure(ShufflingFigure shufflingFigure) {
        boolean editState = shufflingFigureService.updateById(shufflingFigure);
        return editState ?  new ResultUtil(ResultMapInfo.EDITSUCCESS) : new ResultUtil(ResultMapInfo.EDITFAIL);
    }

}
